package architecture;

//_MEM_ForwardingUnit
public class _MEM_ForwardingUnit{
	MyInt EX_MEM_RegisterRd;
	MyInt MEM_WB_RegisterRd;
	MyInt MEM_WB_RegWrite;
	MyInt MEM_WB_MemToReg;
	
	MyInt forwardC;
	
	boolean forwardingFailureC;
	MyBoolean mem_is_forwarding;
	
	void setforwardC(){
		forwardC.i=0;
		forwardingFailureC=false;
		
		int total_forwardC=0;
		
		if(MEM_WB_RegWrite.i==1
				&&EX_MEM_RegisterRd.i==MEM_WB_RegisterRd.i){
			total_forwardC=1;
		}

		if(total_forwardC==1){
			if(MEM_WB_MemToReg.i==1){
				forwardC.i=1;
			}
			else forwardC.i=2;
		}
	}
	void clockEvent(){
		setforwardC();
		if(!mem_is_forwarding.b){
			if(forwardC.i!=0){
				forwardingFailureC=true;
				forwardC.i=0;
			}
		}
	}
	void dump(){
		System.out.println("--------");
		System.out.println("_MEM_ForwardingUnit:");
		System.out.println("EX_MEM_RegisterRd:"+EX_MEM_RegisterRd);
		System.out.println("MEM_WB_RegisterRd:"+MEM_WB_RegisterRd);
		System.out.println("MEM_WB_RegWrite:"+MEM_WB_RegWrite);
		System.out.println("MEM_WB_MemToReg:"+MEM_WB_MemToReg);
		System.out.println("forwardC:"+forwardC);
		System.out.println("--------");
	}
}